package com.thread;

public class SyncApiDemo4 {
    public static void main(String[] args) {
        Boo boo = new Boo();

        //new Thread(() -> boo.methodA()).start();
        //Lambda表达式来简化代码
        new Thread(boo::methodA).start();

        //new Thread(() -> boo.methodB()).start();
        //Lambda表达式来简化代码
        new Thread(boo::methodB).start();
    }
}

class Boo {
    public synchronized void methodA() {
        try {
            Thread thread = Thread.currentThread();
            System.out.println(thread.getName() + "正在执行A方法");
            Thread.sleep(5000);
            System.out.println(thread.getName() + "执行A方法完毕");
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

    public synchronized void methodB() {
        try {
            Thread thread = Thread.currentThread();
            System.out.println(thread.getName() + "正在执行B方法");
            Thread.sleep(5000);
            System.out.println(thread.getName() + "执行B方法完毕");
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

}
